//
//  TabbarView.swift
//  波形图demo
//
//  Created by apple on 2021/2/22.
//

import SwiftUI

struct Claim: Equatable {
    var id: Int
    var description: String
}

struct TabbarView: View {
    
    @State var selectedClaim: Claim?
    
    var claims = [Claim(id: 0, description: "value 1"),
                  Claim(id: 1, description: "value 2"),
                  Claim(id: 2, description: "value 3")]
    
    var body: some View {
        
        Spacer()
        
        List(claims, id:\.id){ claim in
            ClaimCell(claim: claim, selected: self.$selectedClaim)
        }.padding()
        .frame(maxHeight: 180)
        .background(Color.gray)
        .cornerRadius(8)
        
        Spacer()
    }
}

struct ClaimCell: View {
    var claim: Claim
    @Binding var selected: Claim?
    
    var body: some View {
        ZStack(){
            claim == selected ? Color.green : Color.white
            Text(claim.description)
                .padding()
        }.onTapGesture {
            self.selected = self.claim
            print("\(self.claim)")
        }
    }
}

struct TabbarView_Previews: PreviewProvider {
    static var previews: some View {
        TabbarView()
    }
}
